import serial #导入模块
#https://www.cnblogs.com/dongxiaodong/p/9992083.html
#https://www.cnblogs.com/shanyou/archive/2012/10/15/2725043.html
#https://sourceforge.net/projects/com0com/
#
class ck_deal():
  def __init__(self,key=1):
    self.key=key
  def open_port(self,port,bps,timex):
    self.port="COM"+port
    self.bps=bps
    self.timex=timex
    try:
      self.seri=serial.Serial(self.port,self.bps,timeout=self.timex)
      self.key=0
    except Exception as e:
      print("异常--",e)
      self.key=1
  def close_port(self):
    self.seri.close()#关闭串口
    self.key=1
  def send_data(self,data):
    self.seri.write(data.encode("gbk")+"\n".encode("gbk"))
  def read_data(self):
    return self.seri.read()

# op=ck_deal("34",115200,5)
# op.open_port()
# for i in range(0,10):
#   op.send_data(str(i))